home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
C
/
Applications
/
InterLaunch 1.1.2
/
src
/
util.c
< prev
Wrap
Text File
|
1995-12-13
|
7KB
|
244 lines
/* ----------------------------------------------------------------------
util.c
---------------------------------------------------------------------- */
#include "the_defines.h"
#include "the_globals.h"
#include "the_prototypes.h"
/* ----------------------------------------------------------------------
LaunchIt
---------------------------------------------------------------------- */
OSErr LaunchIt(FSSpec theApp, ProcessSerialNumber *serialNum)
{
LaunchParamBlockRec theLaunchParams;
OSErr errLaunching;
theLaunchParams.launchBlockID = extendedBlock;
theLaunchParams.launchEPBLength = extendedBlockLen;
theLaunchParams.launchFileFlags = 0;
theLaunchParams.launchControlFlags = launchContinue + launchNoFileFlags;
theLaunchParams.launchAppSpec = &theApp;
theLaunchParams.launchAppParameters = nil;
errLaunching = LaunchApplication(&theLaunchParams);
if (!errLaunching)
*serialNum = theLaunchParams.launchProcessSN;
return(errLaunching);
}
/* ----------------------------------------------------------------------
OpenCP
---------------------------------------------------------------------- */
OSErr OpenCP(FSSpec cdevSpec, OSType theCreator)
{
short i, vRefNum;
long dirID;
long gestaltAnswer;
long found;
OSErr result, myErr;
AppleEvent aeEvent; // event to create
AEDesc myAddressDesc;
AEDesc aeDirDesc;
AEDesc listElem;
AEDesc fileList;
FSSpec dirSpec;
AliasHandle dirAlias;
AliasHandle fileAlias;
ProcessSerialNumber process;
result = ScheduleFinder();
if (result != noErr)
return(result);
result = Gestalt(gestaltAppleEventsAttr, &gestaltAnswer);
if (result != noErr)
return(result);
if (!BitTst(&gestaltAnswer,31 - gestaltAppleEventsPresent))
return(result);
result = FindFolder(kOnSystemDisk, kControlPanelFolderType, kDontCreateFolder,
&vRefNum, &dirID);
if (result != noErr)
return(result);
if (FindAProcess(TYPE_FINDER, CREATOR_SYSTEM, &process))
return procNotFound;
myErr = AECreateDesc(typeProcessSerialNumber, (Ptr) &process,
sizeof(process), &myAddressDesc);
if (myErr) return myErr;
myErr = AECreateAppleEvent(kAEFinderEvents, kAEOpenSelection,
&myAddressDesc, kAutoGenerateReturnID, kAnyTransactionID,
&aeEvent);
if (myErr) return myErr;
FSMakeFSSpec(cdevSpec.vRefNum, cdevSpec.parID, nil, &dirSpec);
NewAlias(nil, &dirSpec, &dirAlias);
NewAlias(nil, &cdevSpec, &fileAlias);
if (myErr = AECreateList(nil, 0, false, &fileList))
return myErr;
HLock((Handle)dirAlias);
AECreateDesc(typeAlias, (Ptr) *dirAlias, GetHandleSize((Handle) dirAlias),
&aeDirDesc);
HUnlock((Handle)dirAlias);
DisposHandle((Handle)dirAlias);
if ((myErr = AEPutParamDesc(&aeEvent, keyDirectObject, &aeDirDesc)) ==
noErr) {
AEDisposeDesc(&aeDirDesc);
HLock((Handle)fileAlias);
AECreateDesc(typeAlias, (Ptr) *fileAlias, GetHandleSize((Handle)fileAlias),
&listElem);
HUnlock((Handle)fileAlias);
DisposHandle((Handle)fileAlias);
myErr = AEPutDesc(&fileList, 0, &listElem);
}
if (myErr) return myErr;
AEDisposeDesc(&listElem);
if (myErr = AEPutParamDesc(&aeEvent, keySelection, &fileList))
return myErr;
myErr = AEDisposeDesc(&fileList);
myErr = AESend(&aeEvent, nil, kAENoReply+kAEAlwaysInteract+kAECanSwitchLayer,
kAENormalPriority, kAEDefaultTimeout, nil, nil);
AEDisposeDesc(&aeEvent);
return myErr;
}
/* ----------------------------------------------------------------------
FindAProcess
---------------------------------------------------------------------- */
OSErr FindAProcess(OSType typeToFind, OSType creatorToFind, ProcessSerialNumberPtr processSN)
{
ProcessInfoRec tempInfo;
OSErr myErr = noErr;
Str31 processName;
FSSpec procSpec;
processSN->lowLongOfPSN = kNoProcess;
processSN->highLongOfPSN = kNoProcess;
tempInfo.processInfoLength = sizeof(ProcessInfoRec);
tempInfo.processName = (StringPtr)&processName;
tempInfo.processAppSpec = &procSpec;
while ((tempInfo.processSignature != creatorToFind ||
tempInfo.processType != typeToFind) ||
myErr != noErr) {
myErr = GetNextProcess(processSN);
if (myErr ==noErr)
GetProcessInformation(processSN, &tempInfo);
}
return(myErr);
}
/* ----------------------------------------------------------------------
ScheduleFinder
---------------------------------------------------------------------- */
OSErr ScheduleFinder(void)
{
ProcessSerialNumber finderPSN; // the finder's psn
OSErr myErr = noErr;
// Get the psn of the Finder
if( FindAProcess(TYPE_FINDER,CREATOR_SYSTEM,&finderPSN) )
return procNotFound;
// Wake the Finder up
myErr = WakeUpProcess( &finderPSN );
if(myErr) return myErr;
// Queue the Finder for activation
myErr = SetFrontProcess( &finderPSN );
if(myErr) return myErr;
return myErr;
}
/* ----------------------------------------------------------------------
QuitIt
---------------------------------------------------------------------- */
OSErr QuitIt(ProcessSerialNumber *proc)
{
OSErr err;
AEAddressDesc target;
AppleEvent theAE,aeReply;
theAE.dataHandle = aeReply.dataHandle = target.dataHandle = nil;
err = AECreateDesc(typeProcessSerialNumber,(Ptr)proc,sizeof(ProcessSerialNumber),&target);
if (err!=noErr)
return err;
err = AECreateAppleEvent(kCoreEventClass,kAEQuitApplication,&target,
kAutoGenerateReturnID,kAnyTransactionID,&theAE);
if (err!=noErr) {
AEDisposeDesc(&target);
return err;
}
err = AESend(&theAE,&aeReply,kAENoReply,kAENormalPriority,kNoTimeOut,nil,nil);
AEDisposeDesc(&target);
AEDisposeDesc(&theAE);
return err;
}
/* ----------------------------------------------------------------------
LocateFile
---------------------------------------------------------------------- */
OSErr LocateFile (OSType fdType, OSType fdCreator, short vRefNum, FSSpec *spec)
{
short index;
CSParam cs;
HFileInfo spec1;
HFileInfo spec2;
Ptr buffer;
OSErr err;
buffer = NewPtr(8192);
if (MemError()) return;
cs.ioNamePtr = NIL;
cs.ioVRefNum = vRefNum;
cs.ioMatchPtr = spec;
cs.ioReqMatchCount = 1;
cs.ioSearchBits = fsSBFlFndrInfo;
cs.ioSearchInfo1 = (CInfoPBPtr)&spec1;
cs.ioSearchInfo2 = (CInfoPBPtr)&spec2;
cs.ioSearchTime = 0;
cs.ioCatPosition.initialize = 0;
cs.ioOptBuffer = buffer;
cs.ioOptBufSize = 8192;
spec1.ioFlFndrInfo.fdType = fdType;
spec1.ioFlFndrInfo.fdCreator = fdCreator;
spec1.ioFlFndrInfo.fdFlags = 0;
*(long *)&spec1.ioFlFndrInfo.fdLocation = 0L;
spec1.ioFlFndrInfo.fdFldr = 0;
spec2.ioFlFndrInfo.fdType = (ResType)0xffffffff;
spec2.ioFlFndrInfo.fdCreator = (ResType)0xffffffff;
spec2.ioFlFndrInfo.fdFlags = 0x4000;
*(long *)&spec2.ioFlFndrInfo.fdLocation = 0;
spec2.ioFlFndrInfo.fdFldr = 0;
DisposePtr(buffer);
return(PBCatSearch(&cs,FALSE));
}